package com.grzx.protocol.handler.event;

import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Component;

import com.grzx.domain.model.EnterpriseThirdAccount;
import com.grzx.domain.model.Member;
import com.grzx.domain.service.EnterpriseThirdAccountService;
import com.grzx.domain.service.MemberService;
import com.grzx.protocol.handler.Handler;
import com.grzx.protocol.message.event.BaseEvent;
import com.grzx.protocol.message.util.Type;

@Component(Type.Event.EVENT_TYPE_UNSUBSCRIBE)
public class UnsubscribeHandler implements Handler {

	@Inject
	private EnterpriseThirdAccountService thirdAccountService;
	
	@Inject
	private MemberService memberService;
	
	@Override
	public String process(Map<String, String> map) {
		BaseEvent request = new BaseEvent(map);
		String ysId = request.getToUserName();
		String openid = request.getFromUserName();
		EnterpriseThirdAccount thirdAccount = thirdAccountService.findByYsId(ysId);
		if (thirdAccount == null) {
			return "";
		}
		Member member = new Member();
		member.setEa_id(thirdAccount.getId());
		member.setOpenid(openid);
		memberService.modifyMemberType(member);
		return "";
	}

}
